package com.zcx.qshop.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.Toast;

import com.zcx.helper.bound.BoundView;
import com.zcx.helper.http.AsyCallBack;
import com.zcx.qshop.QSApplication;
import com.zcx.qshop.R;
import com.zcx.qshop.conn.JsonSharecouponAsyGet;
import com.zcx.qshop.view.TitleView;

/**
 * Created by Administrator on 2015/9/3 0003.
 */
public class CompleteOrderActivity extends QSActivity implements View.OnClickListener{

    public static OnShareSuccessListener onShareSuccessListener;

    @BoundView(R.id.title_view) private TitleView titleView;

    @BoundView(R.id.complete_order_qq) private View qq;

    @BoundView(R.id.complete_order_qzone) private View qzone;

    @BoundView(R.id.complete_order_wx) private View wx;

    @BoundView(R.id.complete_order_wxf) private View wxf;

    @BoundView(R.id.complete_shoping) private View shoping;

    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_complete_order);

        titleView.showStyle(TitleView.Style.FULL);

        titleView.showType(TitleView.Type.BACK_TWO, TitleView.Type.NAME_ONE);

        titleView.setTitleName("确认订单");

        titleView.setOnTitleItemClickListener(new TitleView.OnTitleItemClickListener() {

            @Override
            public void onBackClick() {

                finish();

            }

        });

        qq.setOnClickListener(this);

        qzone.setOnClickListener(this);

        wx.setOnClickListener(this);

        wxf.setOnClickListener(this);

        shoping.setOnClickListener(this);

        onShareSuccessListener = new OnShareSuccessListener() {

            @Override
            public void onShareSuccess() {

                new JsonSharecouponAsyGet(QSApplication.QSPreferences.readUid(), new AsyCallBack<Integer>(){

                    @Override
                    public void onSuccess(String toast, int type, Integer o) throws Exception {

                        Toast.makeText(CompleteOrderActivity.this, "获取了" + o +"元优惠卷，QShop，让生活更轻松!", Toast.LENGTH_LONG).show();

                        onClick(shoping);

                    }

                }).execute(CompleteOrderActivity.this);

            }

        };

    }

    @Override
    public void onClick(View v) {

        switch (v.getId()){

            case R.id.complete_order_qq:

                QSApplication.ShareAction.shareQQ(this);

                break;

            case R.id.complete_order_qzone:

                QSApplication.ShareAction.shareQzone(this);

                break;

            case R.id.complete_order_wx:

                QSApplication.ShareAction.shareWX(this);

                break;

            case R.id.complete_order_wxf:

                QSApplication.ShareAction.shareWXF(this);

                break;

            case R.id.complete_shoping:

//                if (ShopCarFragment.onShopCarChangeListener != null) {
//
//                    ShopCarFragment.onShopCarChangeListener.onShopCarChange();
//
//                }

                QSApplication.INSTANCE.finishActivity(ConfirmOrderActivity.class);

                finish();

                break;

        }

    }

    @Override
    protected void onDestroy() {

        onShareSuccessListener = null;

        super.onDestroy();

    }

    public interface OnShareSuccessListener{

        public void onShareSuccess();

    }

}
